package cn.xrj.springcloud.controller;



import cn.xrj.springcloud.service.QcpageService;
import cn.xrj.springcloud.pojo.Qcpage;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 51job招聘信息表 前端控制器
 * </p>
 *
 * @author xrj
 * @since 2019-12-13
 */
@RestController
public class QcpageProviderController {
    @Autowired
    QcpageService qcpageService;

    @Autowired
    DiscoveryClient client;

    @GetMapping("/qcpage/getAll")
    public List<Qcpage> getAll(){
        List<Qcpage> list= qcpageService.list();
        return list;
    }

    @GetMapping("/qcpage/getById/{id}")
    @HystrixCommand(fallbackMethod="hystrixGetById")
    public Qcpage getById(@PathVariable("id")Integer id){
        Qcpage qcpage=qcpageService.getById(id);
        if(qcpage==null){
            throw new RuntimeException();
        }
        return qcpage;
    }

    //Hystrix熔断器备用方法，当上述方法不可用时调用此方法迅速返回信息，实现服务熔断，不至于服务雪崩
    public Qcpage hystrixGetById(@PathVariable("id")Integer id){
        Qcpage qcpage=new Qcpage()
                .setId(id)
                .setJob("未查询到该id相关信息")
                .setPlace("未查询到该id相关信息")
                .setCompany("未查询到该id相关信息")
                .setData("未查询到该id相关信息")
                .setDbsource("未查询到该id相关信息")
                .setSalar("未查询到该id相关信息");
        return qcpage;
    }

    @DeleteMapping("/qcpage/deleteById/{id}")
    public boolean deleteById(@PathVariable("id")Integer id){
        boolean flag=qcpageService.removeById(id);
        return flag;
    }
}

